<?php
	$lp_root_path = './';

	define('INSIDE', true);
	include($lp_root_path . 'extension.inc');
	include($lp_root_path . 'common.'.$phpEx);
	
	include_once ($lp_root_path ."classes/templates.class.".$phpEx);
	$dentro=check_user();
	if (isset($_REQUEST ['Registro']))
	{
	header('Location: register.'.$phpEx);

	}
	if (isset($_REQUEST ['Enviar']))
	{

		$email = make_safe($_POST['email']);
		$password = $_POST['password'];
		include_once ($lp_root_path ."classes/users.class.".$phpEx);
		$users = array_pop(Users::list_users("`email`='".$email."'"));
		
		if ($users!=null  and $users->get_password()==md5($password))
			{
			
			$_SESSION['id_usuario'] = $users->get_id();
	       	$_SESSION['usuario']    = $users->get_rol();
			$_SESSION['nick']		= $users->nick;
			$_SESSION['pass']		= $users->get_password ();
			$dentro = true;
			
			}
		else {
			echo 'password Incorrecto';
			}
	}
	
	//Creamos objeto de clase plantilla para generar el html	
	if (!$dentro){	
		$template=new Template();
		$template->template_index();}
	else{
		
		switch ($mode)
		{
		case 'full_ajax':
		{
			if (!check_admin()){header('Location: index.'.$phpEx);	}
			$template=new Template();
			$template->pantallaFullAjax();
			break;
		}
		case 'sugerencias':
			{
			if (!check_admin()){header('Location: index.'.$phpEx);	}
			$template=new Template();
			$template->pantallaSugerencias();
			break;
			}
		case 'administrar':
			{
			if (!check_admin()){header('Location: index.'.$phpEx);	}
			$template=new Template();
			$template->pantallaAdministrar();
			break;
			}
		case 'testing':
			{
			if (!check_admin()){header('Location: index.'.$phpEx);	}
			$template=new Template();
			$template->pantallaTesting();
			break;
			}
		case 'salir':
			{

			session_destroy();
			header('Location: '.$lp_root_path.'index.php');
			exit();
			break;
	
			} 
		case 'universo':
			{
			if (!check_user()){header('Location: index.'.$phpEx);	}
			$template=new Template();
			$template->template_univers();
			break;
			}
		case 'alianza':
			{
			if (!check_user()){header('Location: index.'.$phpEx);	}
			$template=new Template();
			$template->pantallaAlianza();
			break;
			}
		default:
			{
			if (!check_user()){header('Location: index.'.$phpEx);	}
			$template=new Template();
			$template->pantallaDefecto();
			break;
			}
		}

		}

	
?>
